// 填写订单-获取预付订单接口

import type { OrderCreateParams, OrderListParams, OrderListResult, OrderLogisticResult, OrderPreResult, OrderResult } from "@/types/order"
import { http } from "@/utils/http"

// 填写订单-获取预付订单接口
export const getMemberOrderPreAPI = () => {
    return http<OrderPreResult>({
        method: 'GET',
        url: '/member/order/pre'
    })
}

// 填写订单-获取立即购买订单接口
export const getMemberOrderPreNowAPI = (data: { skuId: string, count: string, addressId?: string }) => {
    return http<OrderPreResult>({
        method: 'GET',
        url: '/member/order/pre/now',
        data
    })
}

// 订单页-提交订单接口(因其他数据不是很重要, 所以这里只定义id)
export const postMemberOrderAPI = (data: OrderCreateParams) => {
    return http<{id: string}>({
        method: 'POST',
        url: '/member/order',
        data
    })
}

// 订单页-获取订单详情接口
export const getMemberOrderByIdAPI = (id: string) => {
    return http<OrderResult>({
        method: 'GET',
        url: `/member/order/${id}`,
    })
}

// 订单页-模拟发货接口-内测版
// 在DEV环境下使用, 仅在订单状态为待发货时, 可模拟发货, 调用后订单状态修改为待收货, 包含模拟物流
export const getMemberOrderConsignmentByIdAPI = (id: string) => {
    return http({
        method: 'GET',
        url: `/member/order/consignment/${id}`
    })
}

// 订单页-确认收货接口(仅在订单状态为待收货时, 才可以调用确认收货接口)
export const putMemberOrderReceiptByIdAPI = (id: string) => {
    return http({
        method: 'PUT',
        url: `/member/order/${id}/receipt`
    })
}

// 订单页-获取订单物流接口(仅在订单状态为待收货、待评价、已完成时, 可获取物流信息)
export const getMemberOrderLogisticsByIdAPI = (id: string) => {
    return http<OrderLogisticResult>({
        method: 'GET',
        url: `/member/order/${id}/logistics`
    })
}

// 删除订单(仅在订单状态为待评价、已完成、已取消时, 可删除订单)
export const deleteMemberOrderAPI = (data: { ids: string[] }) => {
    return http({
        method: 'DELETE',
        url: '/member/order',
        data
    })
}

// 订单列表页-获取订单列表接口(参数: 订单状态)
export const getMemberOrderAPI = (data: OrderListParams) => {
    return http<OrderListResult>({
        method: 'GET',
        url: '/member/order',
        data,
    })
}

// 订单页-取消订单接口(仅在订单状态为待付款时, 可取消订单)
export const putMemberOrderAPI = (id: string, data: {cancelReason: string}) => {
    return http<OrderListResult>({
        method: 'PUT',
        url: `/member/order/${id}/cancel`,
        data,
    })
}

// 订单页-再次购买接口
export const getMemberOrderRepurchaseByIdAPI = (id: string) => {
 return http<OrderPreResult>({
   method: 'GET',
   url: `/member/order/repurchase/${id}`,
 })
}